/*
 *  utilities.c
 *  PriceCompareDS
 *
 *  Created by Stacy Haponik on 5/28/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include <stdio.h>
#include <string.h>
#include <fat.h>


int numberOfLinesInFile(FILE *myFile){
	int ch, prev = '\n' // so empty files have no lines 
	, lines = 0;
	while ( (ch = fgetc(myFile)) != EOF ) // Read all chars in the file. 
	{
		if ( ch == '\n' )
		{
			++lines; // Bump the counter for every newline. 
		}
		prev = ch; // Keep a copy to later test whether... 
	}
	fclose(myFile);
	if ( prev != '\n' ) // ...the last line did not end in a newline. 
	{
		++lines; // If so, add one more to the total. 
	}
	return lines;
}
